package com.daodao.daodaoschedule.infrastructure.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daodao.daodaoschedule.domain.wechat.WechatSendConfig;
import com.daodao.daodaoschedule.infrastructure.constant.WechatMessageTypeEnum;
import com.daodao.daodaoschedule.infrastructure.dao.entity.WechatSendConfigPO;
import com.daodao.daodaoschedule.infrastructure.dao.mapper.WechatSendConfigMapper;
import com.daodao.daodaoschedule.infrastructure.repository.WechatSendConfigRepository;
import com.daodao.daodaoschedule.infrastructure.util.BeanCopyUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author mal
 * @date 2023-02-15 15:10
 */
@Repository
@AllArgsConstructor
public class WechatSendConfigRepositoryImpl implements WechatSendConfigRepository {

    private final WechatSendConfigMapper wechatSendConfigMapper;


    @Override
    public WechatSendConfig getMessageTemplate(WechatMessageTypeEnum messageType, Long accountId) {
        WechatSendConfigPO wechatSendConfigPO = wechatSendConfigMapper.selectOne(new QueryWrapper<WechatSendConfigPO>()
                .lambda()
                .eq(WechatSendConfigPO::getAccountId, accountId)
                .eq(WechatSendConfigPO::getTemplateType, messageType)
        );
        return BeanCopyUtils.copyBean(wechatSendConfigPO, WechatSendConfig.class);
    }
}
